package com.example.mobifin_busticket;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class Util {
	private Util() {
		// Not used
	}

	public static boolean emailValidation(String emailstring) {
		Pattern emailPattern = Pattern.compile(".+@.+\\.[a-z]+");
		Matcher emailMatcher = emailPattern.matcher(emailstring);
		return emailMatcher.matches();
	}

	public static void errorFieldcreationSeatselect(Context mContext,
			LinearLayout llChilderror, int noofField, String errorMessage) {
		String[] errorText = null;
		errorText = errorMessage.split(":");
		llChilderror.removeAllViews();
		for (int i = 0; i < noofField; i++) {
			TextView tv = new TextView(mContext);
			if (i == 0) {
				tv.setPadding(0, 0, 0, 10);
			} else {
				tv.setPadding(0, 0, 0, 0);
			}
			tv.setTextColor(mContext.getResources().getColor(R.color.black));
			if (i == 0) {
				tv.setText(errorText[i]);
			} else {
				tv.setText((i) + ". " + errorText[i]);
			}
			llChilderror.addView(tv);
		}
	}

	public static void onClickUserMenu(Context context, ListView list) {
		final Animation fadeinanim = AnimationUtils.loadAnimation(context,
				R.anim.custom_menu_list_slideout_top);
		final Animation fadeoutanim = AnimationUtils.loadAnimation(context,
				R.anim.custom_menu_list_slideout_top);

		if (list.getVisibility() == View.VISIBLE) {
			list.setVisibility(View.GONE);
			list.setAnimation(fadeinanim);
		} else {
			list.setAnimation(fadeoutanim);
			list.setVisibility(View.VISIBLE);
		}

	}

	/*public static void onlistitemclick(Context ctx, int position,
			ListView listmenu) {
		if (position == 0) {
			TicketCancellationDialog dialog = new TicketCancellationDialog(ctx);
			dialog.show();
		} else if (position == 1) {
			PrintTicketDialog printdialog = new PrintTicketDialog(ctx);
			printdialog.show();
		}

		if (listmenu.getVisibility() == View.VISIBLE) {
			listmenu.setVisibility(View.GONE);

		} else {
			listmenu.setVisibility(View.VISIBLE);

		}
	}
*/
	public static void mListHide(ListView listview) {
		if (listview.getVisibility() == View.VISIBLE) {
			listview.setVisibility(View.GONE);
		}
	}

	public static void hideSoftKeyboard(Context ctx, View view) {
		InputMethodManager imm = (InputMethodManager) ctx
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
	}

}
